home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / tde31.zip / CFGCOLOR.C < prev    next >
C/C++ Source or Header  |  1993-08-29  |  15KB  |  532 lines

  1. /*
  2.  * Customize the colors in tde.
  3.  *
  4.  * Author:        Frank Davis
  5.  * Date:          July 21, 1991
  6.  * Compiler:      MSC 6.0a and QuickC 2.51
  7.  *
  8.  * This program is released into the public domain.  You may distribute
  9.  * it freely, Frank Davis
  10.  */
  11.  
  12.  
  13. /********    EXTREMELY IMPORTANT   ************/
  14. /*
  15.  * If you modify tde, it is your responsibility to find the offset of
  16.  * "static int colors" in function "hw_initialize" in file "main.c" in your
  17.  * new executable, tde.exe.
  18.  *
  19.  * If you don't change the default colors, search for the following string (a
  20.  * hexadecimal integer array) in your new executable file:
  21.  *
  22.  *  7000 0700
  23.  *
  24.  * Then, replace COLOR_OFFSET with your new one and recompile tdecfg
  25.  * with the new offset.
  26.  */
  27. /*******     EXTREMELY IMPORTANT   ************/
  28.  
  29.  
  30. #include <bios.h>
  31. #include <dos.h>
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36. #include "tdecfg.h"
  37. #include "cfgcolor.h"
  38.  
  39.  
  40. /*
  41.  * Default color settings.  Incidentally, I'm color blind (mild red-green) and
  42.  * the default colors look fine to me.
  43.  */
  44. COLORS colour = {
  45.    "$colors",
  46.    { { HERC_REVERSE, HERC_NORMAL, HERC_UNDER, HERC_REVERSE, HERC_REVERSE,
  47.      HERC_HIGH, HERC_NORMAL, HERC_NORMAL, HERC_HIGH, HERC_HIGH, HERC_HIGH,
  48.      HERC_REVERSE, HERC_REVERSE, HERC_NORMAL },
  49.    { COLOR_HEAD, COLOR_TEXT, COLOR_DIRTY, COLOR_MODE, COLOR_BLOCK,
  50.      COLOR_MESSAGE, COLOR_HELP, COLOR_WRAP, COLOR_EOF, COLOR_CURL, COLOR_RULER,
  51.      COLOR_POINTER, COLOR_TEXT, COLOR_OVRS } }
  52. };
  53.  
  54.  
  55. extern struct vcfg cfg;         /* video stuff */
  56. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  57. extern long color_offset;
  58.  
  59. COLORS temp_colours;            /* play around with colors in this array */
  60. static int index;               /* 0 = Monochrome colors, 1 = color colors */
  61.  
  62.  
  63. /*
  64.  * Name:    tdecolor
  65.  * Date:    July 21, 1991
  66.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  67.  *          variables  2) show the user a color sample  3) make the changes
  68.  *          permanent if desired.
  69.  */
  70. void tdecolor( void )
  71. {
  72.    initialize_color( );
  73.    show_init_sample( );
  74.    change_colors( );
  75.    restore_overscan( cfg.overscan );
  76. }
  77.  
  78.  
  79. /*
  80.  * Name:    initialize
  81.  * Date:    July 21, 1991
  82.  * Notes:   Set up all of the global variables.
  83.  */
  84. void initialize_color( void )
  85. {
  86.  
  87.    fseek( tde_exe, color_offset, SEEK_SET );
  88.    fread( (void *)&temp_colours, sizeof( COLORS ), 1, tde_exe );
  89.  
  90.    if (cfg.color == FALSE)
  91.       index = 0;
  92.    else
  93.       index = 1;
  94.  
  95.    fields[0].color = temp_colours.clr[index][HELP];
  96.    fields[1].color = temp_colours.clr[index][HEAD];
  97.    fields[2].color = temp_colours.clr[index][TEXT];
  98.    fields[3].color = temp_colours.clr[index][CURL];
  99.    fields[4].color = temp_colours.clr[index][DIRTY];
  100.    fields[5].color = temp_colours.clr[index][WARNING];
  101.    fields[6].color = temp_colours.clr[index][MODE];
  102.    fields[7].color = temp_colours.clr[index][WRAP];
  103.    fields[8].color = temp_colours.clr[index][CEOF];
  104.    fields[9].color = temp_colours.clr[index][OVERSCAN];
  105.    fields[10].color = temp_colours.clr[index][RULER];
  106.    fields[11].color = temp_colours.clr[index][RULER_PTR];
  107.    fields[12].color = temp_colours.clr[index][BLOCK];
  108.    fields[13].color = temp_colours.clr[index][HILITED_FILE];
  109.  
  110.    fields[0].show_me = show_help_color;
  111.    fields[1].show_me = show_fileheader_color;
  112.    fields[2].show_me = show_text_color;
  113.    fields[3].show_me = show_curl_color;
  114.    fields[4].show_me = show_dirty_color;
  115.    fields[5].show_me = show_warning_color;
  116.    fields[6].show_me = show_mode_color;
  117.    fields[7].show_me = show_wrapped_color;
  118.    fields[8].show_me = show_eof_color;
  119.    fields[9].show_me = show_overscan_color;
  120.    fields[10].show_me = show_ruler_color;
  121.    fields[11].show_me = show_rulerptr_color;
  122.    fields[12].show_me = show_block_color;
  123.    fields[13].show_me = show_hilitedfile_color;
  124. }
  125.  
  126.  
  127. /*
  128.  * Name:    restore_overscan
  129.  * Date:    April 1, 1993
  130.  */
  131. void restore_overscan( int overscan )
  132. {
  133.    ASSEMBLE {
  134.         mov     ah, 0x0b                /* function 0x0b */
  135.         mov     bl, BYTE PTR overscan   /* get new overscan color */
  136.         xor     bh, bh
  137.         push    bp
  138.         int     VIDEO_INT               /* video interrupt = 10h */
  139.         pop     bp
  140.    }
  141. }
  142.  
  143.  
  144. /*
  145.  * Name:    show_init_sample
  146.  * Date:    July 21, 1991
  147.  * Notes:   Draw all of the sample screens.
  148.  */
  149. void show_init_sample( void )
  150. {
  151. char *sample;
  152. int  line;
  153. int  i;
  154. int  j;
  155. int  k;
  156. int  l;
  157. char temp[6];
  158. char far *p;
  159.  
  160.    xygoto( -1, -1 );
  161.    sample = sample_screen[0];
  162.    for (line=0; sample != NULL; ) {
  163.       s_output( (char far *)sample, line, 0, 7 );
  164.       sample = sample_screen[++line];
  165.    }
  166.    for (i=0; i<NUM_COLORS; i++)
  167.       (*fields[i].show_me)();
  168.    sample = field_screen[0];
  169.    for (line=12, i=1; sample != NULL; line++,i++) {
  170.       s_output( (char far *)sample, line, 0, 7 );
  171.       sample = field_screen[i];
  172.    }
  173.    p = (char far *)temp;
  174.    for (i=0,k=0,line=17; i<8; i++, line++) {
  175.       for (j=0,l=0; j<16; j++, k++,l+=5) {
  176.          color_number( temp, k );
  177.          s_output( p, line, l, k );
  178.       }
  179.    }
  180.    for (i=0; i<NUM_COLORS; i++) {
  181.       color_number( temp, fields[i].color );
  182.       s_output( p, fields[i].line, fields[i].col, fields[i].color );
  183.    }
  184. }
  185.  
  186.  
  187. /*
  188.  * Name:    color_number
  189.  * Date:    July 21, 1991
  190.  * Passed:  dest:  buffer to store the color sample
  191.  *          num:   attribute number
  192.  * Notes:   Show the use what the foreground and background colors look like.
  193.  */
  194. void color_number( char *dest, int num )
  195. {
  196. int i, j, k;
  197. char temp[6];
  198.  
  199.    strcpy( dest, "[   ]" );
  200.    itoa( num, temp, 10 );
  201.    i = strlen( temp );
  202.    j = 4 - i;
  203.    for (k=0; i > 0; i--,j++, k++)
  204.       dest[j] = temp[k];
  205. }
  206.  
  207.  
  208. /*
  209.  * Name:    current_color_number
  210.  * Date:    July 21, 1991
  211.  * Passed:  dest:  buffer to store the color sample
  212.  *          num:   attribute number
  213.  * Notes:   Put '*' around the sample color to give the user an idea of where
  214.  *          the current field is.
  215.  */
  216. void current_color_number( char *dest, int num )
  217. {
  218. int i, j, k;
  219. char temp[6];
  220.  
  221.    strcpy( dest, "*   *" );
  222.    itoa( num, temp, 10 );
  223.    i = strlen( temp );
  224.    j = 4 - i;
  225.    for (k=0; i > 0; i--,j++, k++)
  226.       dest[j] = temp[k];
  227. }
  228.  
  229.  
  230. /*
  231.  * Name:    show_help_color
  232.  * Date:    July 21, 1991
  233.  */
  234. void show_help_color( void )
  235. {
  236. int color;
  237. int line;
  238.  
  239.    color = fields[0].color;
  240.    for (line=1; line <10; line++)
  241.       hlight_line( 1, line, 37, color );
  242.    hlight_line( 1,  10, 13, color );
  243.    hlight_line( 25, 10, 13, color );
  244. }
  245.  
  246.  
  247. /*
  248.  * Name:    show_fileheader_color
  249.  * Date:    July 21, 1991
  250.  */
  251. void show_fileheader_color( void )
  252. {
  253.    hlight_line( 41, 1, 38, fields[1].color );
  254. }
  255.  
  256.  
  257. /*
  258.  * Name:    show_text_color
  259.  * Date:    July 21, 1991
  260.  */
  261. void show_text_color( void )
  262. {
  263. int color;
  264.  
  265.    color = fields[2].color;
  266.    hlight_line( 41, 3, 38, color );
  267. /*   hlight_line( 41, 5, 38, color );  */
  268. }
  269.  
  270.  
  271. /*
  272.  * Name:    show_curl_color
  273.  * Date:    July 21, 1991
  274.  */
  275. void show_curl_color( void )
  276. {
  277.    hlight_line( 41, 4, 38, fields[3].color );
  278. }
  279.  
  280.  
  281. /*
  282.  * Name:    show_dirty_color
  283.  * Date:    July 21, 1991
  284.  */
  285. void show_dirty_color( void )
  286. {
  287.    hlight_line( 41, 5, 38, fields[4].color );
  288. }
  289.  
  290.  
  291. /*
  292.  * Name:    show_warning_color
  293.  * Date:    July 21, 1991
  294.  */
  295. void show_warning_color( void )
  296. {
  297.    hlight_line( 41, 9, 38, fields[5].color );
  298. }
  299.  
  300.  
  301. /*
  302.  * Name:    show_mode_color
  303.  * Date:    July 21, 1991
  304.  */
  305. void show_mode_color( void )
  306. {
  307.    hlight_line( 41, 10, 26, fields[6].color );
  308. }
  309.  
  310.  
  311. /*
  312.  * Name:    show_wrapped_color
  313.  * Date:    July 21, 1991
  314.  */
  315. void show_wrapped_color( void )
  316. {
  317.    hlight_line( 67, 10, 12, fields[7].color );
  318. }
  319.  
  320.  
  321. /*
  322.  * Name:    show_eof_color
  323.  * Date:    July 21, 1991
  324.  */
  325. void show_eof_color( void )
  326. {
  327.    hlight_line( 41, 8, 38, fields[8].color );
  328. }
  329.  
  330.  
  331. /*
  332.  * Name:    show_overcan_color
  333.  restore_overscan
  334.  * Date:    April 1, 1993
  335.  */
  336. void show_overscan_color( void )
  337. {
  338. int overscan;
  339.  
  340.    overscan = fields[9].color;
  341.    restore_overscan( overscan );
  342. }
  343.  
  344.  
  345. /*
  346.  * Name:    show_ruler_color
  347.  * Date:    July 21, 1991
  348.  */
  349. void show_ruler_color( void )
  350. {
  351.    hlight_line( 41, 2, 21, fields[10].color );
  352.    hlight_line( 63, 2, 16, fields[10].color );
  353. }
  354.  
  355.  
  356. /*
  357.  * Name:    show_rulerptr_color
  358.  * Date:    July 21, 1991
  359.  */
  360. void show_rulerptr_color( void )
  361. {
  362.    hlight_line( 62, 2, 1, fields[11].color );
  363. }
  364.  
  365.  
  366. /*
  367.  * Name:    show_block_color
  368.  * Date:    July 21, 1991
  369.  */
  370. void show_block_color( void )
  371. {
  372. int color;
  373. int line;
  374.  
  375.    color = fields[12].color;
  376.    for (line=6; line <8; line++)
  377.       hlight_line( 41, line, 38, color );
  378. }
  379.  
  380.  
  381. /*
  382.  * Name:    show_hilitedfile_color
  383.  * Date:    July 21, 1991
  384.  */
  385. void show_hilitedfile_color( void )
  386. {
  387.    hlight_line( 14, 10, 11, fields[13].color );
  388. }
  389.  
  390.  
  391. /*
  392.  * Name:    change_colors
  393.  * Date:    July 21, 1991
  394.  * Notes:   Real workhorse function of the utility.  Get a key and then
  395.  *          figure out what to do with it.
  396.  */
  397. void change_colors( void )
  398. {
  399. int  c;
  400. int  area;
  401. int  new_color;
  402. int  i;
  403. char temp[6];
  404. char far *p;
  405.  
  406.    p = (char far *)temp;
  407.    area = 0;
  408.    current_color_number( temp, fields[area].color );
  409.    s_output( p, fields[area].line, fields[area].col, fields[area].color );
  410.    xygoto( fields[area].col+3, fields[area].line );
  411.    for (c=0; c != F3  &&  c != F10  &&  c != ESC;) {
  412.       new_color = FALSE;
  413.       c = getkey( );
  414.       switch (c) {
  415.          case RTURN :
  416.          case DOWN  :
  417.             color_number( temp, fields[area].color );
  418.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  419.             ++area;
  420.             if (area > 13)
  421.                area = 0;
  422.             current_color_number( temp, fields[area].color );
  423.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  424.             xygoto( fields[area].col+3, fields[area].line );
  425.             break;
  426.          case UP    :
  427.             color_number( temp, fields[area].color );
  428.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  429.             --area;
  430.             if (area < 0)
  431.                area = 13;
  432.             current_color_number( temp, fields[area].color );
  433.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  434.             xygoto( fields[area].col+3, fields[area].line );
  435.             break;
  436.          case LEFT :
  437.             --fields[area].color;
  438.             if (area == 9) {
  439.                if (fields[area].color < 0)
  440.                   fields[area].color = 15;
  441.             } else {
  442.                if (fields[area].color < 0)
  443.                   fields[area].color = 127;
  444.             }
  445.             new_color = TRUE;
  446.             break;
  447.          case RIGHT :
  448.             ++fields[area].color;
  449.             if (area == 9) {
  450.                if (fields[area].color > 15)
  451.                   fields[area].color = 0;
  452.             } else {
  453.                if (fields[area].color > 127)
  454.                   fields[area].color = 0;
  455.             }
  456.             new_color = TRUE;
  457.             break;
  458.          case PGUP :
  459.             if (area == 9)
  460.                break;
  461.             fields[area].color -= 16;
  462.             if (fields[area].color < 0)
  463.                fields[area].color = (fields[area].color & 0x000f) + 0x70;
  464.             new_color = TRUE;
  465.             break;
  466.          case PGDN :
  467.             if (area == 9)
  468.                break;
  469.             fields[area].color += 16;
  470.             if (fields[area].color > 127)
  471.                fields[area].color = fields[area].color & 0x000f;
  472.             new_color = TRUE;
  473.             break;
  474.          case F2 :
  475.  
  476.             /*
  477.              * get back the original colors and display
  478.              */
  479.             fields[0].color = colour.clr[index][HELP];
  480.             fields[1].color = colour.clr[index][HEAD];
  481.             fields[2].color = colour.clr[index][TEXT];
  482.             fields[3].color = colour.clr[index][CURL];
  483.             fields[4].color = colour.clr[index][DIRTY];
  484.             fields[5].color = colour.clr[index][WARNING];
  485.             fields[6].color = colour.clr[index][MODE];
  486.             fields[7].color = colour.clr[index][WRAP];
  487.             fields[8].color = colour.clr[index][CEOF];
  488.             fields[9].color = colour.clr[index][OVERSCAN];
  489.             fields[10].color = colour.clr[index][RULER];
  490.             fields[11].color = colour.clr[index][RULER_PTR];
  491.             fields[12].color = colour.clr[index][BLOCK];
  492.             fields[13].color = colour.clr[index][HILITED_FILE];
  493.             for (i=0; i<NUM_COLORS; i++) {
  494.                color_number( temp, fields[i].color );
  495.                s_output( p, fields[i].line, fields[i].col, fields[i].color );
  496.                (*fields[i].show_me)();
  497.             }
  498.             current_color_number( temp, fields[area].color );
  499.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  500.             break;
  501.       }
  502.       if (new_color) {
  503.          current_color_number( temp, fields[area].color );
  504.          s_output( p, fields[area].line, fields[area].col, fields[area].color );
  505.          (*fields[area].show_me)();
  506.       }
  507.    }
  508.  
  509.    /*
  510.     * write changes to "tde.exe" if user presses F10.
  511.     */
  512.    if (c == F10) {
  513.       temp_colours.clr[index][HELP]         = fields[0].color;
  514.       temp_colours.clr[index][HEAD]         = fields[1].color;
  515.       temp_colours.clr[index][TEXT]         = fields[2].color;
  516.       temp_colours.clr[index][CURL]         = fields[3].color;
  517.       temp_colours.clr[index][DIRTY]        = fields[4].color;
  518.       temp_colours.clr[index][WARNING]      = fields[5].color;
  519.       temp_colours.clr[index][MODE]         = fields[6].color;
  520.       temp_colours.clr[index][WRAP]         = fields[7].color;
  521.       temp_colours.clr[index][CEOF]         = fields[8].color;
  522.       temp_colours.clr[index][OVERSCAN]     = fields[9].color;
  523.       temp_colours.clr[index][RULER]        = fields[10].color;
  524.       temp_colours.clr[index][RULER_PTR]    = fields[11].color;
  525.       temp_colours.clr[index][BLOCK]        = fields[12].color;
  526.       temp_colours.clr[index][HILITED_FILE] = fields[13].color;
  527.       fseek( tde_exe, color_offset, SEEK_SET );
  528.       fwrite( (void *)&temp_colours, sizeof( COLORS ), 1, tde_exe );
  529.    }
  530.    cls( );
  531. }
  532.